﻿using MediatR;
using SmartMedicalCare.API.Write.Applications.Commands.一级科室;
using SmartMedicalCare.Domain;
using SmartMedicalCare.ErronCode;
using SmartMedicalCare.Infrastructure.Implaction;

namespace SmartMedicalCare.API.Write.Applications.CommandHandlers.一级科室
{
    public class AddDepartmentCommandHandler : IRequestHandler<AddDepartmentCommand, APIResult<int>>
    {
        private readonly IBaseRespository<DepartmentModel> depRep;

        public AddDepartmentCommandHandler(IBaseRespository<DepartmentModel> depRep)
        {
            this.depRep = depRep;
        }

        public async Task<APIResult<int>> Handle(AddDepartmentCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();
            DepartmentModel dep = new DepartmentModel();
            dep.HospitalId = request.HospitalId;
            dep.Name = request.Name;
            dep.Intro = request.Intro;
            dep.Status = request.Status;
            dep.CreateTime = DateTime.Now;
            dep.IsDeleted = false;
            dep.Css = 1;
            dep.CreateName = request.CreateName;

            await depRep.AddAsync(dep);
            return await Task.FromResult(result);
        }
    }
}
